Now put the following code in the .aspx.cs file (explained in code):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{
//get reference of your webservice
myservice.country ct = new myservice.country();
// str is an XML String which will hold all the countries in xml format
string str = ct.GetCountries();
// add first item in dropdownlist
drpCNT.Items.Add("-Select-");
//Create an XML Document and load your XML
XmlDocument doc = new XmlDocument();
doc.LoadXml(str);
//Get your nodes, here our node in Table because webservice will give us following format
// http://www.webservicex.net/country.asmx/GetCountries
XmlNodeList nodes = doc.DocumentElement.SelectNodes("//Table");
//Iterates for xml nodes and add them in dropdownlist
foreach (XmlNode node in nodes)
{
drpCNT.Items.Add(node["Name"].InnerText);
}
}
}
}